package com.enjoy.jvm.hotspot.src.share.vm.runtime;

import com.enjoy.jvm.hotspot.src.share.tools.DataTranslate;
import com.enjoy.jvm.hotspot.src.share.vm.utilities.BasicType;
import lombok.Data;

@Data
public class StackValue {

    /**
     * 数据类型
     */
    private int type;

    /**
     * float
     * long
     */
    private byte[] data;

    /**
     * 数据
     * 1.小于4B，全部用int
     * 2.double两个int存
     */
    private int val;

    /**
     * 存储引用类型
     */
    private Object object;


    public StackValue(int type, int val) {
        this.type = type;
        this.val = val;
    }

    public StackValue(int type, Object val) {
        this.type = type;
        this.object = val;
    }

    public Object getData(){
        switch (type){
            case BasicType.T_FLOAT:
                return DataTranslate.byteToFloat(data);
            case BasicType.T_LONG:
                return DataTranslate.bytesToLong(data);
            case BasicType.T_INT:
                return val;

        }
        return null;
    }
}
